package com.itheima.jspdemo.servlet;

import com.itheima.jspdemo.pojo.Brand;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

// 三要素:继承重写注解
@WebServlet("/testjstl")
public class TestJSTLServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 为什么重写doGet? 直接请求servlet
        // 模拟从数据库拿数据
        List<Brand> listBrand  = new ArrayList();
        listBrand.add(new Brand(1,"三只松鼠","三只松鼠",100,"三只松鼠，好吃不上火",1));
        listBrand.add(new Brand(2,"优衣库","优衣库",200,"优衣库，服适人生",0));
        listBrand.add(new Brand(3,"小米","小米科技有限公司",1000,"为发烧而生",1));
        // Servlet 特长：写业务  弱点: 不擅长展示数据
        // 克服servlet弱点  请求转发JSP，让JSP去做页面展示  forward转发的意思
        // 请求转发之前，需要把集合放入req对象中
        // / 代表从哪里开始找这个资源
        req.setAttribute("brands",listBrand);
        req.getRequestDispatcher("/jstl-brand.jsp").forward(req,resp);
    }
}
